//
//  BidInvestRecordListCell.swift
//  cxd4iphone
//
//  Created by hexy on 12/23/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let wrapEdges: UIEdgeInsets = UIEdgeInsetsMake(10, 10, -10, -10)
    static let margin: CGFloat         = 10
    static let topViewHeight: CGFloat  = xx_height(30)
    
    static let col1Width: CGFloat      = xx_width(65)
    static let col2Width: CGFloat      = xx_width(80)
    
    static let col3Width: CGFloat      = (xx_screenWidth() - 2 * kConstraints.margin) - kConstraints.col1Width - kConstraints.col2Width - kConstraints.col4Width
    static let col4Width: CGFloat      = xx_width(60)
}


class BidInvestRecordListCell: BaseTableViewCell {

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        self.selectionStyle = .None
    }
    
    override func updateUI(viewModel: BaseCellViewModel) {
        
        guard let vm = (viewModel as? BidInvestRecordCellViewModel) else { return }
        
//        xx_print(vm.bidInvestRecordModel)
        investorLabel.text = vm.bidInvestRecordModel.investUser!
        moneyLabel.text = vm.bidInvestRecordModel.money!
        timeLabel.text = "\(vm.bidInvestRecordModel.time!) |"
        typeLabel.text = vm.bidInvestRecordModel.status!
    }
    
    override func makeUI() {
        
        self.accessoryType = .None
        
//                let wrap = UIView(bgColor: UIColor.orangeColor())
        let wrap = UIView()
        
        contentView.addSubview(wrap)
        wrap.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(kConstraints.wrapEdges)
        }
        
        let line = UIView(bgColor: Define.separatorColor)
        contentView.addSubview(line)
        line.snp_makeConstraints { (make) -> Void in
            
            make.left.bottom.right.equalTo(contentView)
            make.height.equalTo(0.5)
        }
        
        
//                let topView = UIView(bgColor: UIColor.orangeColor())
        let topView = UIView()
        
        wrap.addSubview(topView)
        topView.snp_makeConstraints { (make) -> Void in
            
            make.top.left.right.equalTo(wrap)
            make.height.equalTo(kConstraints.topViewHeight)
        }
        
//                let col1 = UIView(bgColor: xx_randomColor())
//                let col2 = UIView(bgColor: xx_randomColor())
//                let col3 = UIView(bgColor: xx_randomColor())
//                let col4 = UIView(bgColor: xx_randomColor())
        let col1 = UIView()
        let col2 = UIView()
        let col3 = UIView()
        let col4 = UIView()
        topView.addSubview(col1)
        topView.addSubview(col2)
        topView.addSubview(col3)
        topView.addSubview(col4)
        
        col1.snp_makeConstraints { (make) -> Void in
            
            make.top.left.bottom.equalTo(topView)
            make.width.equalTo(kConstraints.col1Width)
        }
        col2.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(topView)
            make.left.equalTo(col1.snp_right)
            make.width.equalTo(kConstraints.col2Width)
        }
        col3.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(topView)
            make.left.equalTo(col2.snp_right)
            make.width.equalTo(kConstraints.col3Width)
        }
        col4.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(topView)
            make.left.equalTo(col3.snp_right)
            make.width.equalTo(kConstraints.col4Width)
        }
        
        col1.addSubview(investorLabel)
        investorLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(col1)//.offset(xx_height(2))
            make.left.equalTo(col1)
        }
        
        col2.addSubview(moneyLabel)
        moneyLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(investorLabel)
            make.left.equalTo(col2)
        }
        
        col3.addSubview(timeLabel)
        timeLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(investorLabel)
            make.right.equalTo(col3)
        }
        
        
        col4.addSubview(typeLabel)
        typeLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(investorLabel)
            make.left.equalTo(col4)
        }
        
 
    }
    
    lazy var investorLabel = UILabel(title: "zhangsan", fontSize: 11)
    lazy var moneyLabel = UILabel(title: "22,222,200.00", fontSize: 11)
    lazy var timeLabel = UILabel(title: "2015-11-12/13:34:45 |", fontSize: 11)
    lazy var typeLabel = UILabel(title: "投资成功", fontColor: Define.darkFontColor, bgColor: nil, fontSize: 11, maxWrapWidth: kConstraints.col4Width)

}
